# -*- coding: utf-8 -*-


from PyQt4.phonon import Phonon


class SongAudio(object):

    def __init__(self):
        super(SongAudio, self).__init__()
        self._media_obj = Phonon.MediaObject(None)
        self._media_obj.setTickInterval(100)
        self._audio_output = Phonon.AudioOutput(Phonon.MusicCategory)
        Phonon.createPath(self._media_obj, self._audio_output)

    def setUrl(self, url):
        self._media_obj.setCurrentSource(Phonon.MediaSource(url.decode('utf-8')))

    def play(self):
        self._media_obj.play()

    def pause(self):
        self._media_obj.pause()

    def stop(self):
        self._media_obj.stop()

    @property
    def media_obj(self):
        return self._media_obj

    @property
    def audio_output(self):
        return self._audio_output
